﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EasyUI.Master" AutoEventWireup="true" CodeBehind="Listcollect.aspx.cs" Inherits="jnagr.Web.ForestPets.Listcollect" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../CSS/IconExtension.css" rel="stylesheet" />
    <script src="../Script/export.js"></script>
    <script src="../Script/username.js"></script>
    <script src="../Script/datetime.js"></script>  
    <script src="../Script/highcharts.js"></script>    
    <script type="text/javascript">
        var colums;
        var otype;
        var ptype;
        var pseries;
        var fmc;
        var year;
        var mleveltype = [{ "id": "4", "text": "国家级", "iconCls": "icon-gj", "checked": true }, { "id": "3", "text": "省级", "iconCls": "icon-sj", "checked": true }, { "id": "2", "text": "市级", "iconCls": "icon-ssj", "checked": true }, { "id": "1", "text": "县级", "iconCls": "icon-xj", "checked": true }];

        $(function () {
            $("#mlevel").combotree({ data: mleveltype, width: 120, valueField: 'id', textField: 'text', editable: false, panelHeight: 'auto', multiple: true, checkbox: true });

            year = new Date().getFullYear();
            $('#jd').combobox({
                onSelect: function (newValue, oldValue) {
                    if (newValue.text == '一季度') {
                        $("#StartTime").datebox("setValue",year+"-1-1");
                        $("#EndTime").datebox("setValue", year + "-3-31");
                    }
                    else if (newValue.text == '二季度') {
                        $("#StartTime").datebox("setValue", year+"-4-1");
                        $("#EndTime").datebox("setValue",year+"-6-30");
                    }
                    else if (newValue.text == '三季度') {
                        $("#StartTime").datebox("setValue",year+"-7-1");
                        $("#EndTime").datebox("setValue",year+"-9-30");
                    }
                    else if (newValue.text == '四季度') {
                        $("#StartTime").datebox("setValue",year+"-10-1");
                        $("#EndTime").datebox("setValue",year+"-12-31");
                    }
                    else if (newValue.text == '当天') {
                        var curr_time = new Date();
                        var strDate = curr_time.getFullYear() + "-";
                        strDate += curr_time.getMonth() + 1 + "-";
                        strDate += curr_time.getDate(); 
                        $("#StartTime").datebox("setValue", strDate);
                        $("#EndTime").datebox("setValue", strDate);
                    }
                }
            });
            $('#ptype').combobox({
                onSelect: function (newValue, oldValue) {
                    if (newValue.text != '成虫') {
                        colums = "[[{ title: '虫名', field: 'hname', width: 150 }, { title: '统计数量', field: 'counts', width: 150 }, { title: '地区', field: 'areas', width: 200 } ]]";

                        $('#tt').datagrid({ columns: eval(colums) });
                    }
                    else {
                        //雄虫数量	雌虫数量	性比	成虫总数
                        colums = "[[{ title: '虫名', field: 'hname', width: 150 }, { title: '雄虫数量', field: 'males', width: 150 }, { title: '雌虫数量', field: 'females', width: 150 }, { title: '成虫总数', field: 't', width: 150,formatter: function (value, row, index) { return parseInt(row.males)+parseInt(row.females);} }, { title: '地区', field: 'areas', width: 200 }]]";

                        $('#tt').datagrid({ columns: eval(colums) });

                    }
                }
            });
            InitGird();
            InitTree();
            

        });
        function InitTree() {
            $('#pt').tree({
                url: '../harmfulinfo/GetHarm.ashx?type=4', //请求数据的页面               
                width: '100%', //宽度                
                lines: true,
                method: 'post',
                queryParams: { "action": "queryt" },
                onClick: function (node) {
                    if (node.text != "") {
                        if (node.type == "1") {
                            $('#idh').val(node.text);
                        }
                        else if (node.type == "2") {
                            $('#city').val(node.bm);
                        }                       
                        
                    }
                },
                onLoadSuccess: function (node, param) {
                    $('#pt').tree("collapseAll");
                    var node = $('#pt').tree("getRoot");
                    if (node)
                        $('#pt').tree("expand", node.target);
                }
            });
        }
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '虫情动态_虫害', //表格标题
                url: 'GetPets.ashx', //请求数据的页面
                sortName: 'inputTime', //排序字段
                idField: 'fp_id', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                onLoadSuccess: function (data) {
                    otype = $('#otype').val();
                    ptype = $('#ptype').combobox('getText');                   
                    var md;
                    tc1 = "";
                    tc2 = "";
                    tc3 = "";
                    tc4 = "";
                    if (otype != '1') {
                        if (ptype == '成虫') {
                            //pseries = $('#idh').val() + "雌虫," + $('#idh').val() + "雄虫," + $('#idh').val() + "成虫";
                            pseries = $('#idh').val() + "雌虫," + $('#idh').val() + "雄虫";
                            pseries = pseries.split(",");
                            WChartJS.init(pseries);
                            $.each(data.rows, function (k, v) {
                                md = v["hname"];
                                tc1 += v["females"] + ",";
                                tc2 += v["males"] + ",";
                                //fmc = parseInt(v["females"]) + parseInt(v["males"]);
                                //tc3 +=  fmc + ",";
                                tc4 += "'" + md + "',";
                            });
                            tc1 = "[" + tc1 + "]";
                            tc2 = "[" + tc2 + "]";
                            //tc3 = "[" + tc3 + "]";
                            tc4 = "[" + tc4 + "]";
                            wchartInstance.series[0].setData(eval(tc1));
                            wchartInstance.series[1].setData(eval(tc2));
                            //wchartInstance.series[2].setData(eval(tc3));
                            wchartInstance.xAxis[0].setCategories(eval(tc4));
                        }
                        else {
                            pseries = $('#idh').val() + "统计数据";
                            pseries = pseries.split(",");
                            WChartJS.init(pseries);
                            $.each(data.rows, function (k, v) {
                                md = v["hname"];
                                tc1 += v["counts"] + ",";
                                tc4 += "'" + md + "',";
                            });
                            tc1 = "[" + tc1 + "]";
                            tc4 = "[" +tc4 + "]";
                            wchartInstance.series[0].setData(eval(tc1));
                            wchartInstance.xAxis[0].setCategories(eval(tc4));
                        }
                    }
                    else {
                        if (ptype == '成虫') {
                            pseries = $('#idh').val() + "雌虫," + $('#idh').val() + "雄虫" ;
                            pseries = pseries.split(",");
                            WChartJS.init(pseries);
                            $.each(data.rows, function (k, v) {
                                md = v["areas"];
                                tc1 += v["females"] + ",";
                                tc2 += v["males"] + ",";
                                //fmc = parseInt(v["females"]) + parseInt(v["males"]);
                                //tc3 += fmc + ",";
                                tc4 += "'" + md + "',";
                            });
                            tc1 = "[" + tc1 + "]";
                            tc2 = "[" + tc2 + "]";
                            //tc3 = "[" + tc3 + "]";
                            tc4 = "[" + tc4 + "]";
                            wchartInstance.series[0].setData(eval(tc1));
                            wchartInstance.series[1].setData(eval(tc2));
                            //wchartInstance.series[2].setData(eval(tc3));
                            wchartInstance.xAxis[0].setCategories(eval(tc4));
                        }
                        else {
                            pseries = $('#idh').val() + "统计数据";
                            pseries = pseries.split(",");
                            WChartJS.init(pseries);
                            $.each(data.rows, function (k, v) {
                                md = v["areas"];
                                tc1 += v["counts"] + ",";
                                tc4 += "'" + md + "',";
                            });
                            tc1 = "[" + tc1 + "]";
                            tc4 = "[" + tc4 + "]";
                            wchartInstance.series[0].setData(eval(tc1));
                            wchartInstance.xAxis[0].setCategories(eval(tc4));
                        }
                    }
                   
                    
                },
                columns: [[{ title: '虫名', field: 'hname', width: 150 }, { title: '统计数量', field: 'counts', width: 150 }, { title: '地区', field: 'areas', width: 200 }]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "queryc" },
                pagination: false, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 100, //默认一页数据条数
                rownumbers: true //行号
            });

            Highcharts.setOptions({
                lang: {
                    contextButtonTitle: "图表导出菜单",
                    decimalPoint: ".",
                    downloadJPEG: "下载JPEG图片",
                    downloadPDF: "下载PDF文件",
                    downloadPNG: "下载PNG文件",
                    downloadSVG: "下载SVG文件",
                    drillUpText: "返回 {series.name}",
                    loading: "加载中",
                    months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                    noData: "没有数据",
                    numericSymbols: ["千", "兆", "G", "T", "P", "E"],
                    printChart: "打印图表",
                    resetZoom: "恢复缩放",
                    resetZoomTitle: "恢复图表",
                    shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
                    thousandsSep: ",",
                    weekdays: ["星期一", "星期二", "星期三", "星期三", "星期四", "星期五", "星期六", "星期天"]
                }
            });
        }


        function getQueryParams(queryParams) {
            var StartTime = $("#StartTime").datebox("getValue");
            var EndTime = $("#EndTime").datebox("getValue");
            var idstr = $("#idstr").val();
            var idh = $("#idh").val();
            var city = $("#city").val();
            var otype = $("#otype").val();
            var mlevel = $("#mlevel").combotree("getValues").toString();
            queryParams.mlevel = mlevel;
            queryParams.StartTime = StartTime;
            queryParams.EndTime = EndTime;
            queryParams.idstr = idstr;
            queryParams.idh = idh;
            queryParams.otype = otype;
            queryParams.city = city;
            return queryParams;

        }
        //增加查询参数，重新加载表格  
        function reloadgrid(t) {
            $('#otype').val(t);
            if (t == '1')
            {
                if ($("#idh").val() == '')
                {
                    $.messager.alert("提示", "请选择虫子！", "info");
                    return;
                }
            }
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');

        }
        var wchartInstance;
        var WChartJS = {
            init: function (chs) {
                var s = "[";
                $.each(chs, function () {
                    //s = s + "{name:'" + this + "',data:[],dataLabels:{enabled: true,rotation: -90,color: '#FFFFFF',align: 'right', x: 4,y: 10,style: { fontSize: '13px',fontFamily: 'Verdana, sans-serif',textShadow: '0 0 3px black'}}},";
                    s = s + "{name:'" + this + "',data:[],dataLabels:{enabled: true}},";
                });
                s = s.substr(0, s.length - 1);
                s = s + "]";
                wchartInstance = new Highcharts.Chart({
                    chart: {
                        renderTo: 'chartArea',
                        type: 'column'
                    },
                    credits: {
                        enabled: false
                    },
                    exporting: {
                        enabled: true
                    },
                    title: {
                        text: '',
                        x: -20 //center
                    },
                    plotOptions: {
                        column: {
                            stacking: 'normal',
                            dataLabels: {
                                enabled: true,
                                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
                            }
                        }
                    },
                    xAxis: {
                        type: 'category',
                        labels: {
                            formatter: function () {
                               return this.value;
                            }
                        }
                    },
                    yAxis: {
                        title: {
                            text: '数值'
                        },
                        stackLabels: {
                            enabled: true,
                            style: {
                                fontWeight: 'bold',
                                color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                            }
                        },
                        plotLines: [{
                            value: 0,
                            width: 1,
                            color: '#808080'
                        }]
                    },
                    tooltip: {
                        formatter: function () {
                            //return '<b>' + this.series.name + '：</b>' + this.y + '<br/> ';
                            var str = '<b>' + this.x + '</b><br>' +
                    this.series.name + ': ' + this.y;
                            if (ptype == '成虫') {
                                str = str + '<br>' +
                        '成虫: ' + this.point.stackTotal;

                            }
                            return str;
                        }
                    },
                    legend: {
                        align: 'center',
                        verticalAlign: 'top',
                        borderWidth: 0
                    },
                    series: eval(s)
                });
            }
        };



    </script>
    <style type="text/css">
        .fitem {
            width: 100%;
            
        }

            .fitem label {
                width:60px;
                line-height: 22px;
            }

            .fitem input {
                width: 120px;
            }
             .dl1 {
            color:green;
            font-weight:bold;
        }
        .dl2 {
            color:blue;
            font-weight:bold;
        }
        .dl3 {
            color:yellow;
            font-weight:bold;
        }
        .dl4 {
            color:red;
            font-weight:bold;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" style="width: 100%; height: 100%;" id="mycon">
        <div region="west" split="true" title="区域检索" style="width: 180px; overflow: scroll" id="west">
            <ul id="pt"></ul>

        </div>
        <div region="center" style="background: #eee; overflow-y: hidden">
             <div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'center'" style="padding: 5px; background: #eee;">
                    <table id="tt">
                    </table>
                </div>
                <div id="chartArea" data-options="region:'south',split:true" style="height: 200px;">
                </div>
            </div>
        </div>
        <div id="tab_toolbar" style="padding: 4px;">
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>
                    <td style="padding-left: 2px">
                        <div>
                            时间从:  
           <input id="StartTime" class="easyui-datebox" style="width: 100px" />
                            到:  
           <input id="EndTime" class="easyui-datebox" style="width: 100px" />
                <select id="jd" class="easyui-combobox" name="jd" style="width:80px;">
                    <option value="季度">季度</option>
                                <option value="一季度">一季度</option>
                                <option value="二季度">二季度</option>
                                <option value="三季度">三季度</option>
                                <option value="四季度">四季度</option>
                    <option value="当天">当天</option>
</select>            
                            <select id="ptype" class="easyui-combobox" name="ptype" style="width:60px;">
                                <option value="所有">所有</option>   
   <option value="卵">卵</option>
                                <option value="幼虫">幼虫</option>
                                <option value="蛹">蛹</option>
                                <option value="成虫">成虫</option>
</select>
                            <input id="mlevel"  name="mlevel" />  
                           <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid(1)">按虫子汇总</a>
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid(2)">按区域汇总</a>
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="Export('excel', $('#tt'));">导出</a>
<input name="idstr" id="idstr" type="hidden" />
                    <input name="idh" id="idh" type="hidden" />
                    <input name="city" id="city" type="hidden" />
                    <input name="st" id="st" type="hidden" />
                    <input name="et" id="et" type="hidden" />
                    <input name="otype" id="otype" type="hidden" value="1" />
                        </div>
                    </td>
                </tr>
            </table>

        </div>       
    </div>
</asp:Content>